package com.mooc.yohoshop.ui.detail;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.blankj.utilcode.util.ConvertUtils;
import com.mooc.yohoshop.R;
import com.mooc.yohoshop.entity.DetailEntity;
import com.mooc.yohoshop.imgload.ImageLoad;

import org.jetbrains.annotations.NotNull;

import java.util.List;

import androidx.annotation.NonNull;
import androidx.viewpager.widget.PagerAdapter;

public class DetailBannerAdapter extends PagerAdapter{

    private List<DetailEntity.ImgValues>list;

    public DetailBannerAdapter(List<DetailEntity.ImgValues>list){
        this.list = list;
    }

    @NonNull
    @NotNull
    @Override
    public Object instantiateItem(@NonNull @NotNull ViewGroup container, int position) {
        View view = LayoutInflater.from(container.getContext()).inflate(R.layout.item_goods_img,container,false);
        ViewGroup.LayoutParams lp = new ViewGroup.LayoutParams(
                ViewGroup.LayoutParams.MATCH_PARENT, ConvertUtils.dp2px(300));
        view.setLayoutParams(lp);
        container.addView(view);
        ImageView img = view.findViewById(R.id.values_vp_img);
        ImageLoad.loadMatch(list.get(position).goods_img_path,img);
        return view;
    }

    @Override
    public void destroyItem(@NonNull @NotNull ViewGroup container, int position, @NonNull @NotNull Object object) {
        container.removeView((View) object);
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public boolean isViewFromObject(@NonNull @NotNull View view, @NonNull @NotNull Object object) {
        return view == object;
    }
}
